<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../../css/btnplus.css" />
		<style type="text/css">
			html,body{ height:100%; }
			.login_form{ padding: 60px 15px 0;}
			.login_form .form li{ margin-top: 22px; padding: 0;}
			.login_form b{ display: block; font-size: 25px; font-weight: 500; color:#333; line-height: 80px;}
			.login_form .form p{ margin-right: 15px;}
			.login_form em{ display:block; line-height: 42px; color: #474747; font-size: 14px;}
			.login_form em a{ color:#474747; font-size:12px; }
			.login_form .btn{ padding-left: 0; padding-right: 0;}

			.fr i { color:#78D49A; }
			.update_pwd .form li{ padding: 0; position: relative;}
			.update_pwd .form li:not(:last-child)::after{position: absolute; content: ""; left: 0; right: 0; bottom: 0; border-bottom: 1px #d4d4d4 solid; transform: scaleY(0.5);}
			.update_pwd .form p{ font-size: 14px; color: #333; line-height: 42px;}
			.update_pwd .form input{ display:block; border: 0; font-size: 14px; color: #474747; padding: 13px 0; width: 100%; background-color: transparent; border-radius: 0;}
			.update_pwd .form button{ display:block; border: 0; font-size: 14px; color: #333; height: 42px; background-color: transparent; border-radius: 0;}
			.update_pwd .form button i{ color: #3262F1; }
			.update_pwd .form span{ display:block; font-size: 12px; color: #999; line-height: 30px;}
			.update_pwd .btn{ padding: 30px 0;}
		</style>
	</head>
	<body>
		<div class="update_pwd login_form">
			<b>设置密码</b>
			<ul class="form">
				<li>
					<div class="m_cell_hd m_cell_primary"><input type="password" name="password" id="password" value="" placeholder="输入新密码" /></div>
				</li>
				<li class="clearfix" style="margin-top:0px;">
					<em class="fl"><a href="javascript:;">6-16位，数字及大小写字母</a></em>
				</li>
			</ul>
			<ul class="btn">
				<button class="d_btn" tapmode="btnpress" id="login-btn" onclick="resetPwd();">下一步</button>
			</ul>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript" src="../../script/md5.js"></script>
	<script type="text/javascript">
		var mobile = '';
		var vcode = '';
		var UIInput;
		var curPwdinputId = 0; //当前密码输入框ID
		var curPwdinputType = 'password'; //当前密码输入框类型
		var keyboardId = 0;//当前键盘ID
		apiready = function() {
			mobile = api.pageParam.mobile;
			vcode = api.pageParam.vcode;
			api.parseTapmode();
			UIInput = api.require('UIInput');
			fnInitUIInput();
			
			api.addEventListener({
                name: 'navitembtn'
            }, function(ret, err) {
                if (ret.type == 'left') {
					api.closeWin({
					});
                }
            });
		}
		function fnInitUIInput(){
			//计算位置
			openUIinput('password','请输入密码','default','password','');
		}
		function openUIinput(domid,placeholder_str,keyboardType,inputType,pwdval){
			//打开UIinput
			var password = $api.byId(domid);
			var password_rect = $api.offset(password);
			UIInput.open({
				rect: {
					x: password_rect.l,
					y: password_rect.t+1,
					w: password_rect.w,
					h: password_rect.h -2
				},
				styles: {
					bgColor: '#fff',
					size: 14,
					color: '#333',
					placeholder: {
						color: '#9f9f9f'
					}
				},
				autoFocus: false,
				maxRows: 1,
				placeholder: placeholder_str,
				keyboardType: keyboardType,
				inputType: inputType,
				fixedOn: api.frameName,
				fixed: false
			}, function(ret) {
				
				if (ret.eventType == 'change') {
					keyboardId = ret.id;
					UIInput.value({
							id: ret.id,
							//msg : '设置输入框的值'
					}, function(ret, err) {
						if (ret) {
							$api.val(password,ret.msg);
						} else {
							//alert(JSON.stringify(err));
						}
					});
				} else if (ret.eventType == 'show' && domid == 'password') {
					curPwdinputId = ret.id; //获取验证码输入框ID
					if(pwdval!='')
					{
						UIInput.value({
							id: curPwdinputId,
							msg: pwdval
						});
					}
				} else {
					//alert(JSON.stringify(ret));
				}
			});
			
		}
		function resetPwd() {
			hideInput();//收起键盘
			var username = mobile;
			var password = $api.val($api.byId('password'));
			if($api.cssVal($api.byId('login-btn'),'opacity')!=1)
			{
				return false;
			}
			if(username=='')
			{
				toast("请返回重试");
				return false;
			}
			if($api.cssVal($api.byId('login-btn'),'opacity')!=1)
			{
				return false;
			}
			//if (mobile.search(/^([0-9]{11})?$/) == -1) {
			if(!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(mobile))) {
				toast('手机号格式错误');
				return false;
			}
			if(password=='')
			{
				toast("请输入密码");
				return false;
			}
			if(password.length < 6 || password.length > 16)
			{
				toast("请输入6-16位密码");
				return false;
			}
			if(!checknumletter(password)) {
				toast("密码只能为数字和大小写字母");
				return false;
			}
			showbtnloading('login-btn');
			var paramsObj = {
				app_key: kAppKey,
				mobile: mobile,
				password: password,
				vcode: vcode,
				regtype: 1
			}
			var _sign = getSign(paramsObj, kAppKey, kAppSecret);
			paramsObj.signature = _sign;
			console.log(JSON.stringify(paramsObj)+'!!!!!!');
			api.ajax({
				url: ApiUrl + '/v1/token/reg',
				method: 'post',
				data: {
					values: paramsObj
				}
			}, function(ret, err) {
				if (ret) {
					var param = {
						mobile: mobile,
						password: password
					};
					openNavWin('#ddd','usertype_win','usertype_frm.html','选择身份',false,false,true,[],param);
				} else {
					console.log(JSON.stringify(err));
					toast(err.body.message);
				}
				hidebtnloading('login-btn','下一步');
			});
		}
		function hideInput(){
			//隐藏键盘
			UIInput.closeKeyboard({
				id: keyboardId
			});
		}
		function closeWin(){
			api.closeWin({
			});
		}
	</script>
</html>